library(osmdata)
## Warning: package 'osmdata' was built under R version 4.0.5
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(sf)
## Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(tmap)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.7
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## Warning: package 'tidyr' was built under R version 4.0.5
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
# examine available features
features_osm<-available_features()
features_osm
## [1] "4wd_only" "abandoned"
## [3] "abutters" "access"
## [5] "addr" "addr:city"
## [7] "addr:conscriptionnumber" "addr:country"
## [9] "addr:county" "addr:district"
## [11] "addr:flats" "addr:full"
## [13] "addr:hamlet" "addr:housename"
## [15] "addr:housenumber" "addr:inclusion"
## [17] "addr:interpolation" "addr:place"
## [19] "addr:postbox" "addr:postcode"
## [21] "addr:province" "addr:state"
## [23] "addr:street" "addr:subdistrict"
## [25] "addr:suburb" "addr:unit"
## [27] "admin_level" "aeroway"
## [29] "agricultural" "alt_name"
## [31] "amenity" "area"
## [33] "atv" "backward"
## [35] "barrier" "basin"
## [37] "bdouble" "bicycle"
## [39] "bicycle_road" "biergarten"
## [41] "boat" "border_type"
## [43] "boundary" "bridge"
## [45] "building" "building:colour"
## [47] "building:fireproof" "building:flats"
## [49] "building:levels" "building:material"
## [51] "building:min_level" "building:part"
## [53] "building:soft_storey" "bus_bay"
## [55] "busway" "castle_type"
## [57] "change" "charge"
## [59] "construction" "construction#Railways"
## [61] "covered" "craft"
## [63] "crossing" "crossing:island"
## [65] "cuisine" "cutting"
## [67] "cycleway" "denomination"
## [69] "destination" "diet"
## [71] "diplomatic" "direction"
## [73] "dispensing" "disused"
## [75] "disused:shop" "drive_in"
## [77] "drive_through" "ele"
## [79] "electric_bicycle" "electrified"
## [81] "embankment" "embedded_rails"
## [83] "emergency" "end_date"
## [85] "entrance" "est_width"
## [87] "fee" "fire_object:type"
## [89] "fire_operator" "fire_rank"
## [91] "foot" "footway"
## [93] "ford" "forestry"
## [95] "forward" "frequency"
## [97] "fuel" "gauge"
## [99] "golf_cart" "goods"
## [101] "hazmat" "healthcare"
## [103] "healthcare:counselling" "healthcare:speciality"
## [105] "height" "hgv"
## [107] "highway" "historic"
## [109] "horse" "ice_road"
## [111] "incline" "industrial"
## [113] "inline_skates" "inscription"
## [115] "internet_access" "junction"
## [117] "kerb" "landuse"
## [119] "lanes" "lanes:bus"
## [121] "lanes:psv" "layer"
## [123] "leaf_cycle" "leaf_type"
## [125] "leisure" "lhv"
## [127] "lit" "location"
## [129] "man_made" "maxaxleload"
## [131] "maxheight" "maxlength"
## [133] "maxspeed" "maxstay"
## [135] "maxweight" "maxwidth"
## [137] "military" "minspeed"
## [139] "mofa" "moped"
## [141] "motor_vehicle" "motorboat"
## [143] "motorcar" "motorcycle"
## [145] "motorroad" "mountain_pass"
## [147] "mtb_scale" "mtb:description"
## [149] "mtb:scale:imba" "name"
## [151] "name:left" "name:right"
## [153] "narrow" "natural"
## [155] "noexit" "non_existent_levels"
## [157] "note" "nudism"
## [159] "office" "official_name"
## [161] "old_name" "oneway"
## [163] "opening_hours" "operator"
## [165] "organic" "oven"
## [167] "overtaking" "parking:condition"
## [169] "parking:lane" "passing_places"
## [171] "place" "power"
## [173] "priority_road" "produce"
## [175] "proposed" "protected_area"
## [177] "psv" "public_transport"
## [179] "railway" "railway:preserved"
## [181] "railway:track_ref" "recycling_type"
## [183] "ref" "religion"
## [185] "residential" "roadtrain"
## [187] "route" "sac_scale"
## [189] "service" "service_times"
## [191] "shelter_type" "shop"
## [193] "short_name" "sidewalk"
## [195] "site" "ski"
## [197] "smoothness" "social_facility"
## [199] "sorting_name" "speed_pedelec"
## [201] "start_date" "step_count"
## [203] "substation" "surface"
## [205] "tactile_paving" "tank"
## [207] "tidal" "toilets:wheelchair"
## [209] "toll" "tourism"
## [211] "tracks" "tracktype"
## [213] "traffic_calming" "traffic_sign"
## [215] "trail_visibility" "trailblazed"
## [217] "trailblazed:visibility" "tunnel"
## [219] "turn" "type"
## [221] "usage" "vehicle"
## [223] "vending" "voltage"
## [225] "water" "wheelchair"
## [227] "wholesale" "width"
## [229] "winter_road" "wood"
# extract tags from a given feature
available_tags("amenity")
## [1] "animal_boarding" "animal_breeding" "animal_shelter"
## [4] "arts_centre" "atm" "baby_hatch"
## [7] "baking_oven" "bank" "bar"
## [10] "bbq" "bench" "bicycle_parking"
## [13] "bicycle_rental" "bicycle_repair_station" "biergarten"
## [16] "boat_rental" "boat_sharing" "brothel"
## [19] "bureau_de_change" "bus_station" "cafe"
## [22] "car_rental" "car_sharing" "car_wash"
## [25] "casino" "charging_station" "childcare"
## [28] "cinema" "clinic" "clock"
## [31] "college" "community_centre" "conference_centre"
## [34] "courthouse" "crematorium" "dentist"
## [37] "dive_centre" "doctors" "dog_toilet"
## [40] "drinking_water" "driving_school" "embassy"
## [43] "events_venue" "fast_food" "ferry_terminal"
## [46] "fire_station" "food_court" "fountain"
## [49] "fuel" "funeral_hall" "gambling"
## [52] "give_box" "grave_yard" "grit_bin"
## [55] "gym" "hospital" "hunting_stand"
## [58] "ice_cream" "internet_cafe" "kindergarten"
## [61] "kitchen" "kneipp_water_cure" "language_school"
## [64] "library" "lounger" "love_hotel"
## [67] "marketplace" "monastery" "motorcycle_parking"
## [70] "music_school" "nightclub" "nursing_home"
## [73] "parcel_locker" "parking" "parking_entrance"
## [76] "parking_space" "pharmacy" "photo_booth"
## [79] "place_of_mourning" "place_of_worship" "planetarium"
## [82] "police" "post_box" "post_depot"
## [85] "post_office" "prison" "pub"
## [88] "public_bath" "public_bookcase" "public_building"
## [91] "ranger_station" "recycling" "refugee_site"
## [94] "restaurant" "sanitary_dump_station" "school"
## [97] "shelter" "shower" "social_centre"
## [100] "social_facility" "stripclub" "studio"
## [103] "swingerclub" "taxi" "telephone"
## [106] "theatre" "toilets" "townhall"
## [109] "toy_library" "university" "vehicle_inspection"
## [112] "vending_machine" "veterinary" "waste_basket"
## [115] "waste_disposal" "waste_transfer_station" "water_point"
## [118] "watering_place"
# Extract Denver cafes
Denver_cafes<- getbb(place_name = "Denver", display_name_contains = "Colorado") %>%
opq() %>%
add_osm_feature("amenity", "cafe")
# Convert to sf object
Denver_cafes_sf<-osmdata_sf(Denver_cafes)
## Error in curl::curl_fetch_memory(url, handle = handle): HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
## Request failed [ERROR]. Retrying in 1 seconds...
# Extract points
Denver_cafes_sf_points<-Denver_cafes_sf %>% pluck("osm_points")
tmap_mode("view")
## tmap mode set to interactive viewing
# Create Map
tm_shape(Denver_cafes_sf_points)+
tm_dots()
Extracting the Starbucks locations:
starbucks<-Denver_cafes_sf_points %>% filter(name=="Starbucks")
tm_shape(starbucks)+
tm_dots()